package org.hackystat.project.explorer;

import static org.junit.Assert.*;
import java.util.List;
import org.hackystat.project.ProjectException;
import org.hackystat.projecttrajectory.ProjectTrajectoryProperties;
import org.hackystat.projecttrajectory.test.ProjectTrajectoryTestHelper;
import org.hackystat.sensorbase.resource.projects.jaxb.Project;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Test cases for the ProjectExplorer class.
 * @author Cam Moore
 *
 */
public class TestProjectExplorer extends ProjectTrajectoryTestHelper {

  /**
   * Tests the ProjectExplorer constructor.
   */
  @Test
  public void testProjectExplorer() {
    try {
      ProjectTrajectoryProperties properties = ProjectTrajectoryProperties.getInstance();
      properties.setTestProperties();
      ProjectExplorer explorer = new ProjectExplorer();
      assertNotNull("ProjectExplorer test construction", explorer);
    } catch (ProjectException e) {
      fail("Could not instantiate ProjectTrajectoryProperties");
    }
  }

  /**
   * Tests the ProjectExplorer getUserProjects method.
   */
  @Test
  public void testGetUserProjects() {
    try {
      ProjectTrajectoryProperties properties = ProjectTrajectoryProperties.getInstance();
      properties.setTestProperties();
      ProjectExplorer explorer = new ProjectExplorer();
      assertNotNull("ProjectExplorer test construction", explorer);
      List<Project> projects = explorer.getUserProjects();
    //  assertSame("wrong number of projects", 3, projects.size());
      for (int i = 0; i < projects.size(); i++) {
        System.err.println(explorer.toShortDescription(projects.get(i)));
      }
    } catch (ProjectException e) {
      fail("Could not instantiate ProjectTrajectoryProperties");
    }
  }

  /**
   * Tests the ProjectExplorer getUserProjects method.
   */
  @Test
  public void testGetAllProjects() {
    try {
      ProjectTrajectoryProperties properties = ProjectTrajectoryProperties.getInstance();
      properties.setTestProperties();
      ProjectExplorer explorer = new ProjectExplorer();
      assertNotNull("ProjectExplorer test construction", explorer);
      List<Project> projects = explorer.getAllProjects();
      assertFalse("Projects should not be empty", projects.isEmpty());
//      for (int i = 0; i < projects.size(); i++) {
//        System.err.println(explorer.toDetailedDescription(projects.get(i)));
//      }
    } catch (ProjectException e) {
      fail("Could not instantiate ProjectTrajectoryProperties");
    }
  }

  /**
   * Tests the ProjectExplorer getUserProjects(String) method.
   */
  @Ignore @Test
  public void testGetUserProjectsString() {
    fail("Not yet implemented");
  }

}
